package com.sn.frame;

import com.sn.constant.Windows;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;

/**
 * @Description:
 * @Author: songbiao
 */
public class ClientFrame extends JFrame {

    public ClientFrame() {
        int x = Windows.DEFAULT_WIDTH/2-(Windows.COMPRESS_WIDTH/2);
        int y = Windows.DEFAULT_HEIGHT/2-(Windows.COMPRESS_HEIGHT/2);
        setBounds(x,y, Windows.COMPRESS_WIDTH,Windows.COMPRESS_HEIGHT);
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public void draw(byte[] data) {
        BufferedImage bufferedImage = null;
        try {
            bufferedImage = ImageIO.read(new ByteArrayInputStream(data));
        } catch (IOException e) {
            System.out.println("byte数组转图片失败");
        }
        this.getGraphics()
                .drawImage(bufferedImage,0,0,Windows.COMPRESS_WIDTH
                        ,Windows.COMPRESS_HEIGHT,this);
    }

}
